package org.karelun.gef.parts;

import java.beans.PropertyChangeListener;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.tools.DirectEditManager;
import org.eclipse.jface.viewers.TextCellEditor;
import org.karelun.gef.directeditor.NodeCellEditorLocator;
import org.karelun.gef.directeditor.NodeDirectEditManager;
import org.karelun.gef.policies.DeleteNodeEditPolicy;
import org.karelun.gef.policies.NodeDirectEditPolicy;

public abstract class BaseAttrPart extends AbstractGraphicalEditPart implements PropertyChangeListener {

	protected static final String PROP_ATTRUBUTE = "ATTARIBUTE"; //$NON-NLS-1$

	protected static final String PROP_METHOD = "METHOD"; //$NON-NLS-1$
	
	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new NodeDirectEditPolicy());
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new DeleteNodeEditPolicy());
	}
	
	@Override
	public void performRequest(Request req) {
		if (RequestConstants.REQ_DIRECT_EDIT.equals(req.getType())) {
			IFigure figure = getFigure();
			
			NodeCellEditorLocator locator = new NodeCellEditorLocator(figure);
			DirectEditManager manager = new NodeDirectEditManager(this,
					TextCellEditor.class, locator);
			manager.show();
		}
		super.performRequest(req);
	}
}
